﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ProjectDirector.Domain.Abstracts;
using ProjectDirector.ViewModels;
using ProjectDirector.Domain.Entities;

namespace ProjectDirector.Controllers
{
    public class ContactController : Controller
    {
        private IProjectDirectorRepository repository;

        public ContactController(IProjectDirectorRepository _repository) {
            this.repository = _repository;
        }
        //
        // GET: /Contact/

        public ActionResult ContactList(int id)
        {
            var contacts = repository.GetContactsByCustomer(id);
            return View(contacts);
        }

        //
        // GET: /Contact/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Contact/Create

        public ActionResult Create(int id)
        {
            var model = new ContactViewModel
            {
                Customer = repository.GetCustomers().SingleOrDefault(x => x.CustomerId == id),
                Contact = new Contact(),
                Titles = repository.GetTitles(),
                JobTitles = repository.GetJobTitles()
            };
            return View(model);
        } 

        //
        // POST: /Contact/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Contact/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Contact/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Contact/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Contact/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
